import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

concrete = pd.read_csv("D:\\新建文件夹\\Python实验报告\\concrete.csv", encoding='gbk')
c_data = concrete.iloc[:, :-1]
c_target = concrete.iloc[:, -1]
c_data_train, c_data_test, c_target_train, c_target_test = train_test_split(c_data, c_target, test_size=0.2, random_state=20)
linear = LinearRegression().fit(c_data_train, c_target_train)
l_pred = linear.predict(c_data_test)
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.figure(figsize=(12, 6))
plt.plot(range(c_target_test.shape[0]), list(c_target_test), color='blue')
plt.plot(range(c_target_test.shape[0]), l_pred, color='red', linewidth=1.5, linestyle='-.')
plt.show()